From 1b9949161b95a121258f9d500d826a2c7ca8b77a Mon Sep 17 00:00:00 2001 From: Paul Woolcock Date: Tue, 6 Dec 2016 10:07:52 -0500 Subject: [PATCH] change this to only emit a warning right now --- src/cargo/util/toml.rs | 17 ++++++++++++++--- tests/build-script.rs | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index fd5a36ca1..18b4d4c6c 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -546,7 +546,7 @@ impl TomlManifest { } // processing the custom build script - let new_build = self.maybe_custom_build(&project.build, &layout.root); + let new_build = self.maybe_custom_build(&project.build, &layout.root, &mut warnings); // Get targets let targets = normalize(&lib, @@ -774,7 +774,10 @@ impl TomlManifest { Ok(replace) } - fn maybe_custom_build(&self, build: &Option, project_dir: &Path) + fn maybe_custom_build(&self, + build: &Option, + project_dir: &Path, + warnings: &mut Vec) -> Option { let build_rs = project_dir.join("build.rs"); match *build { @@ -783,7 +786,15 @@ impl TomlManifest { Some(StringOrBool::String(ref s)) => Some(PathBuf::from(s)), None => { match fs::metadata(&build_rs) { - Ok(ref e) if e.is_file() => Some(build_rs.into()), + // Enable this after the warning has been visible for some time + // Ok(ref e) if e.is_file() => Some(build_rs.into()), + Ok(ref e) if e.is_file() => { + warnings.push("`build.rs` files in the same directory \ + as your `Cargo.toml` will soon be treated \ + as build scripts. Add `build = false` to \ + your `Cargo.toml` to prevent this".into()); + None + }, Ok(_) => None, Err(_) => None, } diff --git a/tests/build-script.rs b/tests/build-script.rs index 021ea0842..01ea55f9a 100644 --- a/tests/build-script.rs +++ b/tests/build-script.rs @@ -2345,8 +2345,12 @@ fn assume_build_script_when_build_rs_present() { authors = [] "#) .file("src/main.rs", r#" + use std::path::Path; fn main() { - println!(include_str!(concat!(env!("OUT_DIR"), "/output"))); + let f = env!("OUT_DIR"); + assert!( + ! Path::new(f).join("output").exists() + ); } "#) .file("build.rs", r#" @@ -2365,7 +2369,14 @@ fn assume_build_script_when_build_rs_present() { p.build(); assert_that(p.cargo("run").arg("-v"), - execs().with_status(0).with_stdout("foo\n")); + execs().with_status(0).with_stderr("\ +warning: `build.rs` files in the same directory as your `Cargo.toml` will soon be treated \ +as build scripts. Add `build = false` to your `Cargo.toml` to prevent this + Compiling builder v0.0.1 ([..]) + Running [..] + Finished [..] + Running [..] +")); } #[test] -- 2.30.2